/***************************************************************************
 *   Copyright (C) 2010 by programmeboy                                    *
 *   programmeboy@gmail.com                                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.                                        *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * 
 ***************************************************************************/


/** \file vt.h
	\author programmeboy
	\date 2011-9-8 18:11
	\modified 
	\brief 
*/

#ifndef __VT_H__
#define __VT_H__

#include <ntddk.h>

VOID NTAPI _VmClear(ULONG PtrLowPart,ULONG PtrHighPart);
VOID NTAPI _VmPtrLd(ULONG PtrLowPart,ULONG PtrHighPart);


ULONG _CR0();
ULONG _CR2();
ULONG _CR3();
ULONG _CR4();

ULONG _CS();
ULONG _DS();
ULONG _ES();
ULONG _FS();
ULONG _GS();
ULONG _SS();

ULONG _ES();

ULONG _Eflags();

VOID _SetCR0(ULONG Value);
VOID _SetCR2(ULONG Value);
VOID _SetCR3(ULONG Value);
VOID _SetCR4(ULONG Value);

ULONG64 _ReadMSR(ULONG MSRIndex);
ULONG64 _WriteMSR(ULONG MSRIndex,ULONG LowPart,ULONG HighPart);
VOID    _VmxOn(ULONG PtrLowPart,ULONG PtrHighPart);
VOID    _VmxOff();
ULONG   _VmFailValid();
ULONG   _VmFailInvalid();
ULONG   _ReadVMCS(ULONG Field);
VOID    _WriteVMCS(ULONG Field, ULONG Value);
VOID    _VmLaunch();

VOID    _Invd();

ULONG   _GdtBase();
ULONG   _IdtBase();
USHORT  _GdtLimit();
USHORT  _IdtLimit();
USHORT  _Ldtr();
USHORT  _TrSelector();

VOID _CpuId(ULONG fn, OUT PULONG ret_eax, OUT PULONG ret_ebx, OUT PULONG ret_ecx, OUT PULONG ret_edx);

VOID    RegSetIdtr(ULONG Base,ULONG Limit);

VOID   _GuestEntryPoint();
VOID   _ExitEventHandler();

VOID   _StartVT();
VOID   _StopVT();
VOID   _GuestExit();

VOID    _DisableWP();
VOID    _EnableWP();

#endif
